package com.icongyou.enterprise.talent_analysis.mapper;

import com.icongyou.enterprise.talent_analysis.entity.HrTemplatePreference;
import org.apache.ibatis.annotations.*;

/**
 * HR用户模板偏好设置 Mapper
 */
@Mapper
public interface HrTemplatePreferenceMapper {
    
    /**
     * 查询HR用户的模板偏好
     */
    @Select("SELECT id, hr_user_id as hrUserId, enterprise_id as enterpriseId, template_id as templateId, " +
            "last_used_at as lastUsedAt, created_at as createdAt, updated_at as updatedAt " +
            "FROM hr_template_preference WHERE hr_user_id = #{hrUserId}")
    HrTemplatePreference selectByHrUserId(@Param("hrUserId") String hrUserId);
    
    /**
     * 插入偏好设置
     */
    @Insert("INSERT INTO hr_template_preference (id, hr_user_id, enterprise_id, template_id, last_used_at, created_at, updated_at) " +
            "VALUES (#{id}, #{hrUserId}, #{enterpriseId}, #{templateId}, #{lastUsedAt}, #{createdAt}, #{updatedAt})")
    int insert(HrTemplatePreference preference);
    
    /**
     * 更新偏好设置
     */
    @Update("UPDATE hr_template_preference SET template_id = #{templateId}, last_used_at = #{lastUsedAt}, updated_at = #{updatedAt} " +
            "WHERE hr_user_id = #{hrUserId}")
    int updateByHrUserId(HrTemplatePreference preference);
    
    /**
     * 清除引用了指定模板的偏好设置（设置为NULL）
     */
    @Update("UPDATE hr_template_preference SET template_id = NULL WHERE template_id = #{templateId}")
    int clearTemplateReference(@Param("templateId") String templateId);
}
